package com.gmrz.uap.common.db;

import org.apache.log4j.Logger;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class DataSourceJndiSingleImpl implements DataSourceShardingFactory {

    private static final Logger LOG = Logger.getLogger(DataSourceJndiSingleImpl.class);

    @Override
    public DataSource getInstance() {
        DataSource dataSource = null;

        String jndi = DataSourceShardingConst.getJndiSingle(DataSourceShardingConst.DATASOURCE_JNDI_CORE_SINGLE);

        try {
            dataSource = (DataSource) new InitialContext().lookup("java:comp/env/" + jndi);
        } catch (NamingException e) {
            LOG.error("获取不到" + jndi + "的JNDI名称",e);
        }
        return dataSource;
    }
}
